<?php 

//随机数 使用马其赛特旋转 可以产生更好的随机数 请不要使用自定义函数 直接使用 mt_rand() 即可 否则PHP提示函数复用！
/*
function getRandNumber($intA,$intB) {
	return mt_rand($intA,$intB);
} 
*/
//SQL安全检测
function SafeRequest($ParaValue) {
	if (strpos($ParaValue," ")=== true or strpos($ParaValue,"%20") === true) {
		return false;
	} else {
		return true;
	}
} 

//对应匹配通用函数
//尝试找A中str,返回B中对应的值, A B可以通过使用l分割成数组
//例 LogicM("wow","123&abc&wow","321&cba&mom","&") 将返回 "mom"
function LogicM($str,$A,$B,$l) {
	$A=explode($l,$A);
	$B=explode($l,$B);
	if (!isset($str)) {
		return false;
	}
	if (count($A)!=count($B)) {
		return false;
	}
	for ($ii=0; $ii<=count($A); $ii=$ii+1) {
		if (($str)==($A[$ii])) {
			return $B[$ii];
		}
	}
	return false;
} 



function formselect($fromname,$v,$t,$s) {
	if (!isset($s)) {
		$s="";
	}

	$sql="select * from ".$fromname." Order by id";
	if (!$result = mysql_query($sql)) { die(mysql_error());}
	$htmltext="<select name='".$t."'>";

	if (mysql_num_rows($result) < 1) {
		$htmltext .= "<option value=''>none</option>";
	} else {
		while ($row = mysql_fetch_array($result)) {
			if (($row["id"])==($s)) {
				$htmltext .= "<option value='".$row[$v]."' selected>".$row[$t]."</option>";
			} else {
				$htmltext .= "<option value='".$row[$v]."' >".$row[$t]."</option>";
			} 
		}
	} 
	$htmltext .="</select>";
	return $htmltext;
} 


function skillselect($n,$s) {
	$text="<select name='".$n."'>";
	$text .= "<option value='未知' >未知</option>";
	for ($r=0; $r<=count($ArrTradeTF); $r=$r+1) {
		if (getFormatTradeName($s)==$ArrTradeTF[$r][$langcode]) {
			$text .= "<option value='".$ArrTradeTF[$r][0]."' selected>".$ArrTradeTF[$r][$langcode]."</option>";
		} else {
			$text .= "<option value='".$ArrTradeTF[$r][0]."' >".$ArrTradeTF[$r][$langcode]."</option>";
		} 
	}
	$text .= "</select>";
	return $text;
}



function proselect($n,$s) {
	$text="<select name='".$n."'>";
	for ($ig=0; $ig<=count($ArrTF); $ig=$ig+1) {
		if (getFormatProfessionName($s)==$ArrTF[$ig][$langcode]) {
			$text .= "<option value='".$ArrTF[$ig][0]."' selected>".$ArrTF[$ig][$langcode]."</option>";
		} else {
			$text .= "<option value='".$ArrTF[$ig][0]."' >".$ArrTF[$ig][$langcode]."</option>";
		} 
	}
	$text .= "</select>";
	return $text;
} 

function raceselect($n,$s) {
	$text="<select name='".$n."'>";
	$text .= "<option value='未知' >未知</option>";
	for ($ig=0; $ig<=count($ArrRaceTF); $ig=$ig+1) {
		if (getFormatRaceName($s)==$ArrRaceTF[$ig][$langcode]) {
			$text .= "<option value='".$ArrRaceTF[$ig][0]."' selected>".$ArrRaceTF[$ig][$langcode]."</option>";
		} else {
			$text .= "<option value='".$ArrRaceTF[$ig][0]."' >".$ArrRaceTF[$ig][$langcode]."</option>";
		} 
	}
	$text .= "</select>";
	return $function_ret;
} 


function eventselect($n,$s) {
	$sarr=array("装备掉落","拓荒成功","推倒BOSS","发现BOSS");
	$text="<select name='".$n."'>";
	for ($ig=0; $ig<=count($sarr); $ig=$ig+1) {
		if ($s==$sarr[$ig]) {
			$text .= "<option value='".$sarr[$ig]."' selected>".$sarr[$ig]."</option>";
		} else {
			$text .= "<option value='".$sarr[$ig]."' >".$sarr[$ig]."</option>";
		} 
	}
	$text .= "</select>";
	return $text;
}


function playerstatusselect($n,$s) {
	$sarr=array("正常","已退会","暂离","待审查","黑名单");
	$text="<select name='".$n."'>";
	for ($ig=0; $ig<=count($sarr); $ig=$ig+1) {
		if ($s==$sarr[$ig]) {
			$text .= "<option value='".$sarr[$ig]."' selected>".$sarr[$ig]."</option>";
		}else{
			$text .= "<option value='".$sarr[$ig]."' >".$sarr[$ig]."</option>";
		} 
	}
	$text .= "</select>";
	return $text;
} 





function adminlevelselect($n,$s) {
	$sarr=array("站点管理员","活动记分员","");
	$sarr=array("0","2","4","3","4");
	$text="<select name='".$n."'>";
	for ($ig=0; $ig<=count($sarr); $ig=$ig+1) {
		if ($s==$sarr[$ig]) {
			$text .= "<option value='".$sarr[$ig]."' selected>".$sarr[$ig]."</option>";
		} else {
			$text .= "<option value='".$sarr[$ig]."' >".$sarr[$ig]."</option>";
		} 
	}
	$text .= "</select>";
	return $text;
} 



function dkpview($t) {
	if ($t>0) {
		return "<span class='green'>".$t."<span>";
	} elseif ($t<0) {
		return "<span class='red'>".$t."<span>";
	} else {
		return "0";
	} 
} 



function eventclass($c) {
	$arrc=array("加入","离开","拾取","分解","仓库","击杀","职务任命","团队事件","个人事件","活动事件");
	$textc="<select name='event_class' onchange='javascript:eventselectclass()'>";
	$textc .= "<option value=' '>请选择</option>";
	for ($i=0; $i<=count($arrc); $i=$i+1) {
		if ($c==$arrc[$i]) {
			$textc .= "<option value='".$arrc[$i]."' selected>".$arrc[$i]."</option>";
		} else {
			$textc .= "<option value='".$arrc[$i]."'>".$arrc[$i]."</option>";
		} 
	}
	$textc .= "</select>";
	return $textc;
} 

function speceventclass($c) {
	$arrc=array("马甲替身","仓库购买","纪律奖惩","DKP转让","其它");
	$textc="<select name='event_class' onchange='javascript:eventselectclass()'>";
	$textc .= "<option value=' '>请选择</option>";
	for ($i=0; $i<=count($arrc); $i=$i+1) {
		if ($c==$arrc[$i]) {
			$textc .= "<option value='".$arrc[$i]."' selected>".$arrc[$i]."</option>";
		} else {
			$textc .= "<option value='".$arrc[$i]."'>".$arrc[$i]."</option>";
		} 
	}
	$textc .= "</select>";
	return $textc;
} 


function raidmemberselect($raidid,$c) {
	$arrPlayers = array();
	if (!is_numeric($raidid)) {
		return false;
	}
	$sql="select * from raid where id=".$raidid;
	if ($result = mysql_query($sql)) {
		$row = mysql_fetch_array($result);
		$arrNames=explode(",",$row["raid_player"]);
		//echo '1';
	} else {
		return false;
	}

	foreach ($arrNames as $name) {
		$sql = "select id player_name from player where player_name='$id'";
		if ($result = mysql_query($sql)) {
			$row = mysql_fetch_array($result);
			$arrPlayers[$name] = $row['id'];
			//echo '1';
		}else{
			$arrPlayers[$name] = $row['id'];
			echo "$id 成员未找到.";
			continue;
		}
	}

	$html="<select class='unuse' name='object'>";
	foreach ($arrPlayers as &$player) {
		if ($c==$player) {
			$html .= "<option value='".$player."' selected>".key($arrPlayers)."</option>";
		} else {
			$html .= "<option value='".$player."'>".key($arrPlayers)."</option>";
		} 
	}
	$html .= "</select>";
	return $html;
} 

//列表行class间隔区分
function linec($i) {
	if (intval($i/2)==$i/2) {
		return "b";
	} else {
		return "a";
	} 
} 

function ReDirectUrl($url){
	echo '<script language=javascript>location.href="'.$url.'"</script>';
}


function checkstr($str){
	if (!get_magic_quotes_gpc()){
		return addslashes(trim($str));
	}else{
		return $str;
	}
}

function checknum($num){
	if (!is_numeric($num)){
		return intval($num);
	}else{
		return $num;
	}
}







//活动列表页,活动类型过滤下拉菜单
function selectraid2() {
$stext .= "<form method='post' action=''><select name='filter' onChange='javascript:submit();'>";
$stext .= "<option value=''>过滤</option>";
$stext .= "<option value='all'>显示全部</option>";
$stext .= "<option value='edit'>未完成编辑的</option>";
$stext .= "<option value='end'>已归档的</option>";
$stext .= "<option value=''>===按DKP分类===</option>";
if ($result = mysql_query("select * from raid_class order by id desc")) {
	while ($row = mysql_fetch_array($result)) {
		$stext=$stext."<option value='D".$row["id"]."'>".$row["class_name"]."</option>";
	}
}
$stext .= "<option value=''>===按制度分类===</option>";
if ($result = mysql_query("select * from ruler order by id desc")) {
	while ($row = mysql_fetch_array($result)) {
		$stext .= "<option value='R".$row["id"]."'>".$row["ruler_name"]."</option>";
	}
}
$stext .= "</select></form>";
return $stext;
} 





//输入一串玩家名字,返回一串玩家ID
//此函数过多SQL请求,需改善效率
function name2id($name) {
	$ArrNames=explode("|",$name);
	for ($im=0; $im<=count($ArrNames); $im=$im+1) {
		if (!(strpos($ArrNames[$im]," ") ? strpos($ArrNames[$im]," ")+1 : 0)>0) {
			$sql="select * from player where player_name='".$ArrNames[$im]."'";
			if ($result3 = mysql_query($sql)) {
				$function_ret=$name2id."<a href='player_detail.php?id=".$result3["id"]."'>".$ArrNames[$im]."</a>|";
			}else{
				$function_ret=$name2id.$ArrNames[$im]."|";
			}
		}
	}
	return substr($name2id,0,strlen($name2id)-1);
} 


//根据输入的玩家ID返回附带链接的该玩家名字
function id2name($id) {
	if (!is_numeric($id) || $id==""){
		return false;
	}
	$sql="select * from player where id=".$id;
	if ($result = mysql_query($sql)) {
		$row = mysql_fetch_array($result);
		$namelink="<a href='player_detail.php?id=".$row["id"]."'>".$row["player_name"]."</a>";
	}else{
		$namelink=$id;
	}
	return $namelink;
}

//根据输入的玩家ID返回该玩家名字
function id2name2($id) {
	if (!is_numeric($id)){
		return false;
	} 
	$sql="select * from player where id=$id";
	if ($result = mysql_query($sql)) {
		$row = mysql_fetch_array($result);
		return $row["player_name"];
	}else{
		return false;
	}
} 










function selecteventdate($d,$c) {
	if (!$Isdate[$d]){
		return false;
	} 
	$sy=strftime("%Y",$d);
	$sm=strftime("%m",$d);
	$sd=$day[$d];
	$textc="<select name='event_date'>";
	for ($ig=1; $ig<=3; $ig=$ig+1){
		$textc .= "<option value='".$DateAdd["d"][$ig-1][$sy."-".$sm."-".$sd]."'>".$DateAdd["d"][$ig-1][$sy."-".$sm."-".$sd]."</option>";
	}
	$textc .= "</select>";
	return $textc;
} 


//name2ids
function getIDByName($name) {
	$sql="select * from player where player_name='".$name."'";
	if ($result = mysql_query($sql)) {
		$row = mysql_fetch_array($result);
		return $row['id'];
	}else{
		return false;
	}
} 




function OutDKP($jt,$et,$id,$raid_actiontime,$raid_time) {
	print "<tr><td>111</td></tr>";
	$sql="select * from raid_event where event_raidid=".$id." and (event_class='拾取' or event_class='仓库')";
	if ($result = mysql_query($sql)) {
		while ($row = mysql_fetch_array($result)) {
			$temptime=$DateDiff["n"][$raid_actiontime][$row["event_time"]]/$raid_time*100;
			print "<tr><td>:".intval($temptime).":</td></tr>";
			if ($temptime<$jt || $temptime>$et){
				$aDKPd=$aDKPd+$row["event_dkp"]/40;
			} 
		}
	}else{
		print "<tr><td>000</td></tr>";
	}

	return $function_ret;
} 



function time_type($tvar,$tt) {
	if (!($isdate[$ttt])){
		$function_ret=""; 
		return $function_ret;
	} 
	switch ($tt){
		case 1://10-10:
		$function_ret=strftime("%m",$ttt)."-".$day[$ttt];
		break;
		case 11://月-日:
		$function_ret=strftime("%m",$ttt)."月".$day[$ttt]."日";
		break;
		case 2://年(2)-月-日 00-10-10:
		$function_ret=substr(strftime("%Y",$ttt),strlen(strftime("%Y",$ttt))-(2))."-".strftime("%m",$ttt)."-".$day[$ttt];
		break;
		case 3://2000-10-10:
		$function_ret=strftime("%Y",$ttt)."-".strftime("%m",$ttt)."-".$day[$ttt];
		break;
		case 33://年(4)-月-日:
		$function_ret=strftime("%Y",$ttt)."年".strftime("%m",$ttt)."月".$day[$ttt]."日";
		break;
		case 4://23:45:
		$function_ret=strftime("%H",$ttt).":".strftime("%M",$ttt);
		break;
		case 44://时:分:
		$function_ret=strftime("%H",$ttt)."时".strftime("%M",$ttt)."分";
		break;
		case 5://23:45:36:
		$function_ret=strftime("%H",$ttt).":".strftime("%M",$ttt).":".strftime("%S",$ttt);
		break;
		case 55://时:分:秒:
		$function_ret=strftime("%H",$ttt)."时".strftime("%M",$ttt)."分".strftime("%S",$ttt)."秒";
		break;
		case 6://10-10 23:45:
		$function_ret=strftime("%m",$ttt)."-".$day[$ttt]." ".$our[$ttt].":".strftime("%M",$ttt);
		break;
		case 66://月-日 时:分:
		$function_ret=strftime("%m",$ttt)."月".$day[$ttt]."日 ".$our[$ttt].":".strftime("%M",$ttt);
		break;
		case 666://月-日 时:分:
		$function_ret=strftime("%m",$ttt)."月".$day[$ttt]."日 ".$our[$ttt]."时".strftime("%M",$ttt)."分";
		break;
		case 7://年(2)-月-日 时:分  00-10-10 23:45:
		$function_ret=substr(strftime("%Y",$ttt),strlen(strftime("%Y",$ttt))-(2))."-".strftime("%m",$ttt)."-".$day[$ttt]." ".$our[$ttt].":".strftime("%M",$ttt);
		break;
		case 8://2000-10-10 23:45:
		$function_ret=strftime("%Y",$ttt)."-".strftime("%m",$ttt)."-".$day[$ttt]." ".$our[$ttt].":".strftime("%M",$ttt);
		break;
		case 88://年(4)-月-日 时:分:
		$function_ret=strftime("%Y",$ttt)."年".strftime("%m",$ttt)."月".$day[$ttt]."日 ".$our[$ttt]."时".strftime("%M",$ttt)."分";
		break;
		case 9://2000-10-10 23:45:45:
		$function_ret=strftime("%Y",$ttt)."-".strftime("%m",$ttt)."-".$day[$ttt]." ".$our[$ttt].":".strftime("%M",$ttt).":".strftime("%S",$ttt);
		$function_ret=$formatdatetime[$time_type];
		break;
		case 99://年(4)-月-日 时:分:秒:
		$function_ret=strftime("%Y",$ttt)."年".strftime("%m",$ttt)."月".$day[$ttt]."日 ".$our[$ttt]."时".strftime("%M",$ttt)."分".strftime("%S",$ttt)."秒";
		break;
		case "aa":
		$function_ret=strftime("%Y",$ttt)."年".strftime("%m",$ttt)."月".$day[$ttt]."日".$WeekDayName[strftime("%w",strftime("%m/%d/%Y %H:%M:%S %p"))+1][true];
		break;
		case 90:
		$function_ret=strftime("%Y",$ttt).strftime("%m",$ttt).$day[$ttt].$our[$ttt].strftime("%M",$ttt).strftime("%S",$ttt);
		break;
		default:

		$function_ret=$ttt;
		break;
	} 
	return $function_ret;
} 


function userlogin() {
	if (!empty($_SESSION['adminname'])){
		echo '<ul><li>系统账号错误,请<a href="AdminLogin.php?Action=Logout">退出登录</a></li></ul>';
	}else{
	echo "	<a name='loginviewbtn' href='Javascript:;'>管理员登录</a>"."\r\n";
    echo "				<div id=\"UesrLogin\">"."\r\n";
    echo  "					<form method=\"post\" action=\"AdminLogin.php?Action=Login\">"."\r\n";
    echo "						<ul><li>账号 <input type=\"text\" name='u_name' size=\"15\"/></li>"."\r\n";
    echo "						<li>密码 <input type=\"password\" name='u_password' size=\"15\"/></li> <li><input type='submit' value='管理员登录' /></li></ul>"."\r\n";
    echo  "					</form>"."\r\n";
    echo "				</div>"."\r\n";	
    return;
	}
}
/*	
	
  if (!isset( $_POST['u_name']) || !isset($_POST['u_passwprd'])){
  	ReDirectUrl('default.php');
  	exit;
   }else{
   	$uname=checkstr($_POST['u_name']); //检查参数 防止注入
   	$upass=checkstr($_POST['u_password']);
   	
   	mysql_select_db('fsdkp',$db_link);
   	$sql="SELECT * from admin where admin_name='".$uname."' and admin_password='".$upass."'";
   $result=mysql_query($sql,$dblink);
  if (mysql_num_rows()>0){
  	$_SESSION['adminname']=$uname;
  	ReDirectUrl('default.php');
  }else{
  	$_SESSION['adminname']=NULL;
  }
   }
}
*/
/*
  if ($_SESSION[$_SESSION[$_SESSION]!="")
  {

    print $_SESSION[$_SESSION[]."<ul><li><a href=\"AdminLogin.php?Action=Logout\">退出登录</a></li></ul>";
  }
    else
  {

    print "	<a name='loginviewbtn' href='Javascript:;'>管理员登录</a>"."\r\n";
    print "				<div id=\"UesrLogin\">"."\r\n";
    print "					<form method=\"post\" action=\"AdminLogin.php\">"."\r\n";
    print "						<ul><li>账号 <input type=\"text\" name='u_name' size=\"15\"/></li>"."\r\n";
    print "						<li>密码 <input type=\"password\" name='u_password' size=\"15\"/></li> <li><input type='submit' value='管理员登录' /></li></ul>"."\r\n";
    print "					</form>"."\r\n";
    print "				</div>"."\r\n";
  } 

  return $function_ret;
} 
*/



//物品简单分类,
function eqpic($item,$tooltip) {
	switch (true){
		case     $instr[$item]["头颅"]>0:
		$picfile="skull.jpg'";
		break;
		case     $instr[$item]["弓"]>0:
		$picfile="bow.jpg'";
		break;
		case     $instr[$item]["靴"]>0 | (strpos($item,"鞋") ? strpos($item,"鞋")+1 : 0)>0:
		$picfile="boots.jpg'";
		break;
		case     $instr[$item]["匕首"]>0:
		$picfile="blade.jpg'";
		break;
		case     $instr[$item]["手套"]>0:
		$picfile="gauntlets.jpg'";
		break;
		case     $instr[$item]["腕"]>0:
		$picfile="bracer.jpg'";
		break;
		case     $instr[$item]["袍"]>0:
		$picfile="shirt.jpg'";
		break;
		case     $instr[$item]["肩"]>0:
		$picfile="shoulder.jpg'";
		break;
		case     $instr[$item]["戒"]>0:
		$picfile="ring.jpg'";
		break;
		case     $instr[$item]["枪"]>0:
		$picfile="rifle.jpg'";
		break;
		case     $instr[$item]["头"]>0 | (strpos($item,"角饰") ? strpos($item,"角饰")+1 : 0)>0:
		$picfile="helmet.jpg'";
		break;
		case     $instr[$item]["腰"]>0:
		$picfile="belt.jpg'";
		break;
		case     $instr[$item]["胸"]>0:
		$picfile="chesta.jpg'";
		break;
		case     $instr[$item]["暗影之击"]>0:
		$picfile="spear.jpg'";
		break;
		case     $instr[$item]["锤"]>0:
		$picfile="hammer.jpg'";
		break;
		case     $instr[$item]["魔典"]>0:
		$picfile="book.jpg'";
		break;
		case     $instr[$item]["封印"]>0 | (strpos($item,"神圣之眼") ? strpos($item,"神圣之眼")+1 : 0)>0:
		$picfile="talisman.jpg'";
		break;
		case     $instr[$item]["腿"]>0 | (strpos($item,"裤") ? strpos($item,"裤")+1 : 0)>0:
		$picfile="pants.jpg'";
		break;
		case     $instr[$item]["纯焰精华"]>0:
		$picfile="potion.jpg'";
		break;
		case     $instr[$item]["盾"]>0 | (strpos($item,"防御") ? strpos($item,"防御")+1 : 0)>0 | (strpos($item,"壁") ? strpos($item,"壁")+1 : 0)>0:
		$picfile="shield.jpg'";
		break;
		case     $instr[$item]["勋章"]>0:
		$picfile="talisman.jpg'";
		break;
		case     $instr[$item]["护手"]>0:
		$picfile="gauntlets.jpg'";
		break;
		case     $instr[$item]["护符"]>0 | (strpos($item,"项圈") ? strpos($item,"项圈")+1 : 0)>0:
		$picfile="necklace.jpg'";
		break;
		case     $instr[$item]["杖"]>0:
		$picfile="staff.jpg'";
		break;
		case     $instr[$item]["斗篷"]>0 | (strpos($item,"披") ? strpos($item,"披")+1 : 0)>0:
		$picfile="cape.jpg'";
		break;
		case     $instr[$item]["勋章"]>0:
		$picfile="talisman.jpg'";
		break;
		case     $instr[$item]["勋章"]>0:
		$picfile="talisman.jpg'";
		break;
		case     $instr[$item]["剑"]>0 | (strpos($item,"刃") ? strpos($item,"刃")+1 : 0)>0:
		$picfile="sword.jpg'";
		break;
		case     $instr[$item]["矿石"]>0:
		$picfile="ore.jpg'";
		break;
		case     $instr[$item]["水晶"]>0:
		$picfile="gem.jpg'";
		break;
		default:
		$picfile="unknow.jpg'";
		break;
	} 

	if ($tooltip!=""){
		$ArrTooltip=explode(";",$tooltip);
		for ($ig=3; $ig<=count($ArrTooltip); $ig=$ig+1){
			switch (true) {
				case         $Instr[$ArrTooltip[$ig]]["|"]>0:
				$tooltipText .="<p>".str_replace("|","<span>",$ArrTooltip[$ig])."</span></p>";
				break;
				case         $Instr[$ArrTooltip[$ig]]["装备："]>0 | (strpos($ArrTooltip[$ig],"使用：") ? strpos($ArrTooltip[$ig],"使用：")+1 : 0)>0:
				$tooltipText .="<p class=\"effect\">".$ArrTooltip[$ig]."</p>";
				break;
				case         $Instr[$ArrTooltip[$ig]]["/"]>0:
				$tooltipText .="<p class=\"GoldText\">".$ArrTooltip[$ig]."</p>";
				break;
				case         $Instr[$ArrTooltip[$ig]]["套装："]>0:
				$tooltipText .="<p class=\"GoldText\">".$ArrTooltip[$ig]."</p>";
				break;
				default:
				$tooltipText .="<p>".$ArrTooltip[$ig]."</p>";
				break;
			} 
		}
		$tooltipText="<h4 class=\"".color2CSS($ArrTooltip[0])."\">".$ArrTooltip[2]."</h4>".$tooltipText;
		$function_ret="<a href='http://db.ngacn.cc/main.php?func=170&spc=1111110&sc_kval=".rawurlencode($item)."' target='_blank'><img src='".strtolower($IconPath.$ArrTooltip[1].$IconExt)."' class='eqpic' alt='".$tooltipText."' /></a>";
	}else{
		$tooltipText=$item;
		$itemID=explode("#",$item);
		if (count($itemID)==1){
			$function_ret="<a href='http://cn.wowarmory.com/item-info.xml?i=".$itemID[1]."' target='_blank'><img name='item' src='images/icon/".$picfile."' class='eqpic' itemID=\"".$itemID[1]."\" alt='".$itemID[0]."' /></a>";
		}else{
			$function_ret="<a href='http://db.ngacn.cc/main.php?func=170&spc=1111110&sc_kval=".rawurlencode($item)."' target='_blank'><img src='images/icon/".$picfile."' class='eqpic' alt='".$tooltipText."' /></a>";
		} 
	} 
	return $function_ret;
} 




function delItemID($strItemName) {
	if ((strpos($strItemName,"#") ? strpos($strItemName,"#")+1 : 0)>0){
		$strT=explode("#",$strItemName);
		return $strT[0];
	}else{
		return $strItemName;
	} 
} 


function color2CSS($color) {
	switch ($color){
		case "ffffffff":
		$function_ret="standard";
		break;
		case "ff1eff00":
		$function_ret="good";
		break;
		case "ff0070dd":
		$function_ret="superior";
		break;
		case "ffa335ee":
		$function_ret="epic";
		break;
		case "ffa335ee":
		$function_ret="legendary";
		break;
	} 
	return $function_ret;
} 



function getInstanceIco($name) {
	$function_ret="<img src='images/icon/key.jpg' />";
	return $function_ret;
} 



function ProPic($code) {
	if (!is_numeric($code)) {return false;}
	switch ($code) {
	case 1:
		$ico = 'warrior.png';
		break;
	case 2:
		$ico = 'rogue.png';
		break;
	case 3:
		$ico = 'hunter.png';
		break;
	case 4:
		$ico = 'paladin.png';
		break;
	case 5:
		$ico = 'shaman.png';
		break;
	case 6:
		$ico = 'druid.png';
		break;
	case 7:
		$ico = 'warlock.png';
		break;
	case 8:
		$ico = 'mage.png';
		break;
	case 9:
		$ico = 'priest.png';
		break;
	case 10:
		$ico = 'deathknight.png';
		break;
	default:
		$ico = 'female.gif';
		break;
	}
	return "<img src='images/icon/".$ico."' class='eqpic' />";
} 



function BaseDKP($pid,$cid) {
	if (is_numeric($pid)){
		$sql="select top 1 * from player_dkp where player_id=".$pid." and raid_class=".$cid;
	}else{
		$sql="select top 1 * from player_dkp where player_name='".$pid."' and raid_class=".$cid;
	}
	if ($result = mysql_query($sql)) {
		return 0;
	}else{
		return $result2["player_Basedkp"];
	} 
} 



//raidclassText
function getRaidClassText($classid) {
	$sql="select * from raid_class where id=".$classid;
	if (!$result = mysql_query($sql)) {
		return "<b>未设置分类</b>";
	}else{
		$row = mysql_fetch_array($result);
		return $row["class_name"];
	}

} 


function raidclassid($cname) {
	if (!SafeRequest($cname)){
		return false;
	} 
	$sql="select top 1 * from raid_class where class_name='".$cname."'";
	if ($result = mysql_query($sql)){
		return false;
	}else{
		return $result2["id"];
	} 
} 
/*

*/

//=============================
//字符过滤函数
//=============================
function htmlencode2($str) {
	if (!isset($str)){
		return "";
	} 
	$l=strlen($str);
	$result="";
	for ($i=1; $i<=$l; $i=$i+1){
		switch (substr($str,$i-1,1)){
			case "<":
			$result .= "&lt;";
			break;
			case ">":
			$result .= "&gt;";
			break;
			case       $chr[13]:
			$result .= "<br />";
			break;
			case       $chr[34]:
			$result .= "&quot;";
			break;
			case "&":
			$result .= "&amp;";
			break;
			case       $chr[32]:
			//result=result+"&nbsp;"
			if ($i+1<=$l && $i-1>0){
				if (substr($str,$i+1-1,1)==chr(32) || substr($str,$i+1-1,1)==chr(9) || substr($str,$i-1-1,1)==chr(32) || substr($str,$i-1-1,1)==chr(9)){
					$result .= "&nbsp;";
				}else{
					$result .= " ";
				} 
			}else{
				$result .= "&nbsp;";
			} 
			break;
			case       $chr[9]:
			$result .= "";
			break;
			default:
			$result .= substr($str,$i-1,1);
			break;
		} 
	}
	return $result;
} 


function showerror($text) {
	print "<div class='message'>";
	print "<h3>产生如下错误导致程序中断:</h3>";
	print "<div>".$text."</div>";
	print "</div>";
	return ;
} 



function showmessage($text) {
	print "<div class='message'>";
	print "<h3>提示信息:</h3>";
	print "<div>".$text."</div>";
	print "</div>";
	return;
} 




//=============================
//通用分页函数 V3.0
//记录集对象rec ;每页显示n条 ; 链接地址m(可带参数) ; 前后显示c个页码后省略
//记录指针移动标准算法: rs.move (request("page")-1)*n
//SULei 2005.1.10
//=============================
function pages($rec,$n,$m,$c) {
	$k="?";
	$s=1;
	$counts=$rec->recordcount;
	if ((strpos($m,"?") ? strpos($m,"?")+1 : 0)>0){
		$k="&amp;"; //没有参数用"?",否则就用"&"
	} 
	if ((${"page"}-$c)>0){
		//向后页码省略计算
		$s=(${"page"}-$c);
		$counts=$counts-($s-1)*$n;
	} 
	for ($i=$s; $i<=$counts; $i=$i+1){
		if (intval(${"page"})==$i){
			$function_ret=$pages."<a href='".$m.$k."page=".$i."' class='CPage' >".$i."</a> "; //打标当前页
		}else{
			$function_ret=$pages."<a href='".$m.$k."page=".$i."'>".$i."</a> ";
		} 
		$counts=$counts-$n;
		if ($counts<1 || $i==${"page"}+$c){
			$max=abs(intval(($rec->recordcount/$n)*-1)); //记录最大页数
			break;
		} 
	}

	if ($max==0) {$max=1;}

	if (intval(${"page"})<1) {
		$CP=1;
	}else{
		$CP=intval(${"page"});
	}

	if (intval(${"page"})<$max && $max>1) {
		return $pages." <a href='".$m.$k."page=".($CP+1)."'>next</a>";
	} 

	if (intval(${"page"})>1) {
		return "<a href='".$m.$k."page=".(${"page"}-1)."'>prev</a> ".$pages;
	}

	if ($max==1) {return "仅一页";} 

	return $pages." [共".$rec->recordcount."条记录,当前第".$CP."/".$max."页,每页".$n."条]";
} 


//根据参数格式化数值
function cPre($Vint) {
	if (!is_numeric($Vint)){
		return "-";
	} 
	if ($Precision=="1"){
		return number_format($Vint,2);
	}else{
		return intval($Vint);
	} 
} 


function formattime($timed) {
	if ($timed<60){
		return $timed."分钟";
	}else{
		return intval($timed/60)."小时".intval(($timed/60-intval($timed/60))*60)."分钟";
	} 
} 


function office2img($strName) {
	if ($strName!=""){
		$ArrStr=explode("|",$strName);
		for ($iy=0; $iy<=count($ArrStr)-1; $iy=$iy+1){
			$ArrNum=explode(",",$ArrStr[$iy]);
			$ttext .= "<img src='images/icon/officer.gif' alt='+".$ArrNum[1]."'>".$ArrNum[0];
		}
	} 
	return $ttext;
}


function lootview($t) {
	if (!isset($t) || $t==""){
		return "-";
	}else{
		$t2=explode("|",$t);
		for ($i=1; $i<=count($t2); $i=$i+1){
			$t3=$t3."<li>[<a href='http://db.ngacn.cc/main.php?func=170&spc=1111110&sc_kval=".rawurlencode($t2[$i])."' target='_blank' onmouseover=\"epicRead('ajax_reader.php?key=".rawurlencode($t2[$i])."',this);\">".$t2[$i]."</a>]</li>";
		}
		return "<ol class='items'>".$t3."</ol>";
	} 
} 


//按角色名查询
function Search() {
 if (!isset($_POST['keyword'])||empty($_POST['keyword'])){
 	echo '<script language=javascript>alert("您还没有输入要查询的角色名！")</script>';
 	ReDirectUrl('default.php');
 	exit;
 }
 if ($_GET['action']!=='Search'){
 	ReDirectUrl('default.php');
 	exit;
 }else{
 	$nametosearch=checkstr($_POST['keyword']);
 	if (strlen($nametosearch)>15){
 		echo '<script language=javascript>alert("要搜索的角色名过长，请重新输入")</script>';
 		ReDirectUrl('default.php');
 		exit;
 	}
 	$sql="SELECT * FROM player where player_name='".$nametosearch."' LIMIT 0,1";
 	$result=mysql_query($sql);
 	if (mysql_num_rows($result)===0){
 		echo '<script language=javascript>alert("指定的角色不存在，请重新输入！")</script>';
 		ReDirectUrl('default.php');
 		exit;
 	}else{
 		$row=mysql_fetch_assoc($result);
 		ReDirectUrl('player_detail.php?id='.$row['id']);
 	}
 	
 }
 
  return $function_ret;
} 

//获得附加Ajax链接的拾取物品
function getLootItemsLink($t) {
	if (!isset($t) || $t==""){
		return "-";
	}else{
		$t2=explode("|",$t);
		for ($i=count($t2); $i>=1; $i=$i-1) {
			if (count($t2)-$i==$MaxShowLootItems) {
				$t3=$t3."... (共".count($t2)."件)";
				break;
			} 
			$t3=$t3."<li>[<a href='http://db.ngacn.cc/main.php?func=170&spc=1111110&sc_kval=".rawurlencode($t2[$i])."' target='_blank' onmouseover=\"epicRead('ajax_reader.php?key=".rawurlencode($t2[$i])."',this);\">".delItemID($t2[$i])."</a>]</li>";
		}
		return "<ol class='items'>".$t3."</ol>";
	}
} 


//获得指定日期的活动计划
function getDatePlans($strDate) {
	$sql="select * from article where article_class='c' and article_date like '%".$DateValue[$strDate]."%' and article_text<>'' order by article_date";
	if ($result = mysql_query($sql)) {
		return false;
	}else{
		while ($row = mysql_fetch_array($result)) {
			$divRaids .= "<div class='aevent'>";
			$divRaids .= "<h4>计划:".$result["article_text"]."</h4>";
			$divRaids .= "</div>";
		}
	}
	return $divRaids;
}


//获得指定日期的活动报告
function getDateRaids($strDate) {
	$sql="select top 10 * from raid where raid_actiontime like '%".$DateValue[$strDate]."%'";
	if ($result = mysql_query($sql)) {
		return false;
	}else{
		while ($row = mysql_fetch_array($result)) {
			$divRaids .= "<div class='aevent'>";
			$divRaids .= "<h4>活动:<a href='raid_report.php?id=".$result["id"]."'>".$result["raid_name"]."</a></h4>";
			$divRaids .= "<span>".$result["raid_plan"]."</span>";
			$divRaids .= "</div>";
		}
	}
	return $divRaids;
} 



//获得指定日期的副本更新事件 TBC Only
function getDateEvents($strDate) {
	if (strftime("%w",$strDate)+1==3){
		//服务器维护日
		$Events .= "<li>卡拉赞</li><li>毒蛇神殿</li><li>黑暗神殿</li><li>海加尔峰</li><li>风暴要塞</li><li>格鲁尔的巢穴</li><li>玛瑟里顿的巢穴</li><li>太阳井高地</li>";
	}
	//if datediff("d",Basedate,strDate)/5=Cint(datediff("d",Basedate,strDate)/5) then '每隔5日
	//	Events=Events& "<li>奥妮克希亚</li>"
	//end if
	if ($datediff["d"][$dateadd["d"][-2][$Basedate]][$strDate]/3==intval($datediff["d"][$dateadd["d"][-2][$Basedate]][$strDate]/3)){
		//每隔3日-1
		$Events .= "<li>祖阿曼</li>";
	}
	return "<ul class='events'>".$Events."</ul>";
} 


//根据兼容表获得当前语言的职业名称
function getFormatProfessionName($strPName) {
	global $ArrTF, $langcode;
	for ($i=0; $i<=count($ArrTF); $i=$i+1){
		for ($ik=0; $ik<=count($ArrTF[$i]); $ik=$ik+1){
			if ($strPName==$ArrTF[$i][$ik]){
				return $ArrTF[$i][$langcode];
			} 
		}
	}
	return "未知";
} 



//根据兼容表获得商业技能名称
function getFormatTradeName($strTradeName) {


  for ($ix=0; $ix<=count($ArrTradeTF); $ix=$ix+1)
  {
    for ($ik=0; $ik<=count($ArrTradeTF[$ix]); $ik=$ik+1)
    {
      if ($strTradeName==$ArrTradeTF[$ix][$ik])
      {

        $function_ret=$ArrTradeTF[$ix][$langcode];
        return $function_ret;

      } 


    }


  }

  $function_ret="未知";
  return $function_ret;
} 


//根据兼容表获得标准的简体中文种族名称
function getFormatRaceName($strRaceName) {
	global $ArrRaceTF, $langcode;
	for ($ir=0; $ir<=count($ArrRaceTF); $ir=$ir+1){
		for ($ik=0; $ik<=count($ArrRaceTF[$ir]); $ik=$ik+1){
			if ($strRaceName==$ArrRaceTF[$ir][$ik]){
				return $ArrRaceTF[$ir][$langcode];
			} 
		}
	}
	return "未知";
}



//获得职业图标
function getProfessionSmallIco($strPName) {
	global $ArrTF;
	foreach ($ArrTF as $row) {
		if ($strPName==$row[0]){
			return "images/icon/".end($row).".gif";
		}
	}
	return "images/icon/1.gif";
}


//获得种族图标
function getRaceSmallIco($strPName) {
	global $ArrRaceTF;
	foreach ($ArrRaceTF as $row){
		if ($strPName==$row[0]){
			return "images/icon/a".end($row).".gif";
		}
	}
	return "images/icon/a1.gif";
} 




function cov2Time($strTime) {
	if (strlen($strTime)==17) {
		return getTimeMRT207($strTime);
	}elseif (is_numeric($strTime) && strlen($strTime)==10) {
		return getTimeRT150($strTime);
	}elseif ($IsDate[$strTime]) {
		return $strTime;
	}else{
		return false;
	} 
} 



//转换CTRT的秒计时间为一般格式
function getTimeRT150($intSecond) {
	if (is_numeric($intSecond)){
		return $DateAdd["s"][$intSecond]["1970-1-1"];
	}else{
		return getTimeMRT207($intSecond);
	}
}



//转换时间为CTRT的秒计
function getRT150Time($ntime) {
	if ($IsDate[$ntime]){
	return $DateDiff["s"]["1970-1-1"][$ntime];
	}else{
	return $DateDiff["s"]["1970-1-1"][time()];
	}
}

//日期格式05/10/08 20:05:00 的正确转换
function getTimeMRT207($strtime) {
	$arrD=explode("/",$strtime);
	if (count($arrD)<2){
		print "errorDateFormat".$d;
	} 
	return "20".substr($arrD[2],0,2)."-".$arrD[0]."-".$arrD[1]." ".substr($arrD[2],3);
}

//获得用于日历的星期几的文字
function getWeekNameCN($wdate) {
	$ArrWeekName=array("","周日","(一)","(二)","(三)","(四)","(五)","(六)");
	return $ArrWeekName[strftime("%w",$wdate)+1];
} 

//标准的英文BOSS名称转换成简体中文
function getBossName($strName) {
	for ($i=0; $i<=count($BossName); $i=$i+1){
		if (trim($strName)==$BossName[$i](0)){
			return $BossName[$i](1);
			break;
		} 
	}
	return "unknow";
} 



//标准英文副本名转缩写
function getInstanceAb($strName) {
	for ($ir=0; $ir<=count($Instance); $ir=$ir+1){
		if (trim($strName)==$Instance[$ir](0)){
			return $Instance[$ir](2);
			break;
		} 
	}
	return trim($strName);
} 

//标准英文副本名装简体中文
function getInstanceName($strName) {
	for ($i=0; $i<=count($Instance); $i=$i+1){
		if (trim($strName)==$Instance[$i](0)){
			return $Instance[$i](1);
			break;
		} 
	}
	return trim($strName);
}



function checkShowInstance($strName) {
	if ((strpos($ShowInstance,$strName) ? strpos($ShowInstance,$strName)+1 : 0)!=0){
		return true;
	}else{
		return false;
	} 
} 



//盗贼 -> 潜行者
function getHeXieProfessionName($strName) {
	if ($strName=="盗贼" && $langcode==0){
		return "潜行者";
	}else{
		return $strName;
	} 
} 


//操作完成提示信息条
function getCueInfo($strtxt) {
	print "<table class='cuebarframe'><tr><td><img src='style/images/cue_left.gif' /></td><td class='cue_info'>".$strtxt."</td><td><img src='style/images/cue_right.gif' /></td></tr></table>";
	return;
}



//获取事件相应图标
function getEventIco($strEventClass) {
	switch ($strEventClass) {
		case "加入":
		$strPicFlieName="";
		break;
		case "离开":
		$strPicFlieName="";
		break;
		case "拾取":
		$strPicFlieName="event1.gif";
		break;
		case "分解":
		$strPicFlieName="event2.gif";
		break;
		case "仓库":
		$strPicFlieName="event2.gif";
		break;
		case "击杀":
		$strPicFlieName="event5.gif";
		break;
		case "首次击杀":
		$strPicFlieName="event5.gif";
		break;
		case "团队事件":
		$strPicFlieName="event6.gif";
		break;
		case "个人事件":
		$strPicFlieName="event7.gif";
		break;
		case "活动事件":
		$strPicFlieName="event6.gif";
		break;
	} 
	$function_ret="<img src='".$StylePath."/images/".$strPicFlieName."' class='eventico' />";
	if ($strPicFlieName=="") {
		return "";
	} 
	return $function_ret;
} 



//识别双字节的字符省略函数
function len2($str) {
	$l=strlen($str);
	$tj=0;
	for ($izj=1; $izj<=$l; $izj=$izj+1){
		$casc=abs($Ascw[substr($str,$izj-1,1)]);
			if ($casc>255){
				$tj=$tj+1;
			} 
		$tj=$tj+1;
	}
	return $tj;
} 




//获得库中指定职业的现有数量
function getClassMemberCount($strClassName) {
	if ($strClassName==""){
		$sql="select player_name from player";
	}else{
		$sql="select player_name from player where player_class='$strClassName'";
	} 
	$count = mysql_query($sql);
	echo mysql_error();
	return mysql_num_rows($count);
}




//标准化一个时间字串 如:05/10/08 19:33:07 or 1224435401 to 2009-12-30 17:56:34
function getStandardDate($str_date) {
	if (!$str_date) return date("Y-m-d H:i:s");
	if (is_numeric($str_date)) {
		return date("Y-m-d H:i:s",($str_date));
	}else{
		return date("Y-m-d H:i:s",strtotime($str_date));
	}
}


function datediff($t1,$t2) {
	return abs(strtotime($t1)-strtotime($t2));
}


function getPlayerLevel($level) {
	global $DefalutPlayerLevel;
	if ($level =='' || !is_numeric($level)) {
		return $DefalutPlayerLevel;
	}else{
		return $level;
	}
}
/*




*/
















/*
function honorselect($n,$s,$t) {
extract($GLOBALS);
if ((strpos($t,"A") ? strpos($t,"A")+1 : 0) || (strpos($t,"联") ? strpos($t,"联")+1 : 0)) {
$sarr=array("无","列兵","下士","中士","军士长","士官长","骑士","骑士中尉","骑士队长","护卫骑士","少校","司令","统帅","元帅","大元帅");
}
else {
$sarr=array("无","侦察兵","步兵","中士","高阶军士","一等军士长","石头守卫","血卫士","军团士兵","百夫长","勇士","中将","将军","督军","高阶督军");
} 
$text="<select name='".$n."'>";
for ($ii=0; $ii<=count($sarr); $ii=$ii+1) {
if ($s==$sarr[$ii]) {
$text=$text."<option value='".$sarr[$ii]."' selected>".$sarr[$ii]."</option>";
}
else {
$text=$text."<option value='".$sarr[$ii]."' >".$sarr[$ii]."</option>";
} 
}
$text=$text."</select>";
$function_ret=$text;
return $function_ret;
} 

*/
?>
